package com.zjxf.controller;

import com.zjxf.base.bean.po.LHNTTravelPlan;
import com.zjxf.base.bean.vo.VoCmsTravelPlan;
import com.zjxf.base.common.JSONResponse;
import com.zjxf.controller.common.BaseController;
import com.zjxf.service.LHNTTravelPlanService;
import com.zjxf.utils.VoChangeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * 我要出征以及出征路线管理
 * Created by lhn on 2021/4/10.
 */
@Validated
@RestController
@AllArgsConstructor
@Api(tags = "LHNTTravelPlaneController", description = "我要出征")
@RequestMapping("/app/travelPlan/")
public class LHNTTravelPlaneController extends BaseController {

    private final LHNTTravelPlanService lhntTravelPlanService;

    /**
     * 保存数据
     *
     * @param savePlan 用户提交表单
     * @return JSONResponse
     */
    @ApiOperation(value = "保存用户数据，日期格式yyyy-MM-dd HH:mm:ss")
    @PostMapping(value = "save")
    public JSONResponse save(@Valid @RequestBody VoCmsTravelPlan.savePlan savePlan) {
        LHNTTravelPlan travelPlan = VoChangeUtils.voChangePo(savePlan);
        lhntTravelPlanService.addTravelPlan(travelPlan);
        return success();
    }

    /**
     * 查询所有路线
     * @return JSONResponse
     */
    @ApiOperation(value = "查询全部路线")
    @PostMapping("findAll")
    public JSONResponse findAllTravelPlan() {
        List<Long> idList = lhntTravelPlanService.findAll();
        return success(idList);
    }
}
